package com.ubi.core.utils;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;

public class TranslateUtil {

    /**
     * 翻译枚举类型
     * 
     * @author lvh 2016年2月6日 上午8:36:41</br>
     * @param list
     * @param skey
     * @param tkey
     * @param e
     * @return void
     */
    public static void translatEnumList(List list, String skey, String tkey, List<HashMap> liste) {

        for (int i = 0; i < list.size(); i++) {
            Object o = list.get(i);
            try {
                String value = BeanUtils.getProperty(o, skey);
                if (!StringUtils.isEmpty(value)) {
                    for (int m = 0; m < liste.size(); m++) {
                        HashMap s = liste.get(m);
                        String typeValue = s.get("type_id").toString();
                        if (typeValue.equals(value)) {
                            BeanUtils.setProperty(o, tkey, s.get("type_name").toString());
                        }
                    }
                }
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e1) {
                continue;
            }

        }
    }
}
